﻿// See https://aka.ms/new-console-template for more information

using System.Text;
using Org.Apache.Rocketmq;
using RocketMQ.Test;

Console.WriteLine("Hello, RocketMQ!");

const string topic = "test-topic";

const string consumerGroup = "test-consumer-group";
var subscription = new Dictionary<string, FilterExpression>
    { { topic, new FilterExpression("*") } };
var pushConsumer = await new PushConsumer.Builder()
    .SetClientConfig(new ClientConfig.Builder()
        .SetEndpoints("localhost:8082")
        .Build())
    .SetConsumerGroup(consumerGroup)
    .SetSubscriptionExpression(subscription)
    .SetMessageListener(new CustomMessageListener())
    .Build();

var producer = await new Producer.Builder()
    .SetTopics(topic)
    .SetClientConfig(new ClientConfig.Builder()
        .SetEndpoints("localhost:8081")
        .Build())
    .Build();

var bytes = Encoding.UTF8.GetBytes("foobar");
var message = new Message.Builder()
    .SetTopic(topic)
    .SetBody(bytes)
    .SetKeys(Guid.NewGuid().ToString())
    .Build();

var sendReceipt = await producer.Send(message);
Console.WriteLine($"Send message successfully, messageId={sendReceipt.MessageId}");

Console.ReadKey();